[Compiler] Fix 'use no memo' to apply recursively to nested functions#35433
[Compiler] Fix 'use no memo' to apply recursively to nested functions#35433sahiee-dev wants to merge 1 commit intofacebook:mainfrom
Conversation
Summary: Fixed bug facebook#35350 where 'use no memo' directive didn't apply recursively to nested functions with component-like names. This caused runtime errors when using render props with libraries like react-virtualized. The fix: 1. Track functions with 'use no memo' in a Set during traversal 2. Before compiling any nested function, check if any ancestor has opted out 3. Allow explicit 'use memo' in nested function to override parent's opt-out Test Plan: - Added 4 new test fixtures covering nested function scenarios - All 1832 existing tests pass with no regressions Fixes: facebook#35350
|
Hi @sahiee-dev! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Fixed bug #35350 where the
'use no memo'directive did not apply recursively to nested functions with component-like names. This caused runtime hook errors when nested functions were compiled and used as render props (e.g. with react-virtualized).The fix:
'use no memo'during traversal'use memo'on a nested function to override the parent opt-outTest Plan:
Fixes: #35350
Summary
The React Compiler previously treated
'use no memo'as applying only to the annotated function. Nested functions with component-like names were still compiled, even when they were intended to be called as plain functions.This caused invalid hook usage at runtime in render prop patterns commonly used by libraries such as react-virtualized.
This change makes
'use no memo'act as a recursive opt-out boundary for nested functions, unless a nested function explicitly opts back in with'use memo'.How did you test this change?
Added new test fixtures under
compiler/packages/babel-plugin-react-compiler/src/tests/fixtures/compiler/:use-no-memo-nested-component.jsuse-no-memo-nested-arrow.jsuse-no-memo-deeply-nested.jsuse-no-memo-nested-with-opt-in.jsRan targeted tests:
yarn snap -p "use-no-memo*"Verification Results
$ yarn snap1832 Tests, 1832 Passed, 0 Failed
Done in 23.93s.